package org.example.sportdemo.controller;

import org.example.sportdemo.entity.Product;
import org.example.sportdemo.entity.ProductCollection;
import org.example.sportdemo.entity.Yonghu;
import org.example.sportdemo.service.ProductService;
import org.example.sportdemo.service.YonghuService;
import org.example.sportdemo.utils.PageUtils;
import org.example.sportdemo.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/yonghu")
public class YonghuController {

    @Autowired
    private YonghuService yonghuService;

    //分页
    @RequestMapping("/page")
    public R page(@RequestParam Map<String, Object> params){

        PageUtils page = yonghuService.queryPage(params);

        R r = new R();
        r.put("page",page);
        return r;
    }

    //新增
    @RequestMapping(value = "/addYonghu")
    public R addYonghu(@RequestBody Yonghu yonghu){
        System.out.println(yonghu);
        yonghuService.addYonghu(yonghu);
        return R.ok().put("yonghu",yonghu);
    }


    @RequestMapping(value = "/updateYonghu")
    public R updateYonghu(@RequestBody Yonghu yonghu){
        System.out.println(yonghu);
        yonghuService.updateYonghu(yonghu);
        return R.ok().put("yonghu",yonghu);
    }


    //根据id查询
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
        Yonghu yonghu = yonghuService.selectById(id);
        return R.ok().put("yonghu",yonghu);
    }

    //删除
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
        yonghuService.deleteByIds(ids);
        return R.ok();
    }


}
